package com.qy.herbagemall.dbutil;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class Dbutil {
    final static String RESOURCE = "mybatis-config.xml";
    public static SqlSession getSqls(){
        try{
            InputStream inputStream = Resources.getResourceAsStream(RESOURCE);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession sqls = sqlSessionFactory.openSession();
            return sqls;
        } catch (IOException e){
            e.printStackTrace();
            System.out.println("创建session会话异常");
        }
        return null;
    }
    public static int getIdNum(){
        int index = 0;
        int num = (int)(Math.random()*9)+1;
        String str = ""+num;
        for (int i = 0; i < 8; i++){
            num = (int)(Math.random()*10);
            str = str + num;
        }
        int n = Integer.parseInt(str);
        return n;
    }
}
